<template>
  <div class="app-container">
      <!-- 正式考试 -->
    <div class="backgroundClass">
        <div style="border-bottom:1px solid #eee;padding-bottom:24px;">
          <span class="title_fontSize"> {{http.indexOf('yingji') != -1?'模拟练习':'正式考试'}}</span>
        </div>
        <div class="content-box">
          <div class="content-title">
            <div class="img_box">
              <img src="@/assets/logo/logo.png" alt="">
              <div class="span">
                {{nickname}}
              </div>
            </div>
            <div class="content-box-title">
              <span>
                稳住心态，沉着答题
              </span>
            </div>
          </div>
          <el-form label-position="left" label-width="73px" class="form">
            <el-form-item label="考试科目:" class="noneMargin">
                <el-select v-model="subject" placeholder="请选择" disabled>
                  <el-option
                    v-for="item in userinfor"
                    :key="item.id"
                    :label="item.subjectTitle"
                    :value='item.subject_id'
                    >
                  </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="考试标准:" class="noneMargin" v-if="obj.考试时长">
              <span>
                {{obj.考试时长.时长}}分钟，{{Number(obj.试题分布.单选.数量) + Number(obj.试题分布.多选.数量) + Number(obj.试题分布.判断.数量)}}题
              </span>
            </el-form-item>
            <el-form-item label="合格标准:" class="noneMargin" v-if="obj.考试时长">
              <span>
                {{obj.分值标准.及格}}分及格(满分{{Number(obj.试题分布.单选.总分) + Number(obj.试题分布.多选.总分) + Number(obj.试题分布.判断.总分)}}分)
              </span>
            </el-form-item>
            <!-- <el-form-item label="出题方式:" v-if="!ksInfo&&title_name=='模拟考试'">
              <el-select v-model="form" placeholder="请选择">
                <el-option
                  label="未答题优先"
                  value='未答题优先'
                  >
                </el-option>
                <el-option
                  label="随机出题"
                  value='随机出题'
                  >
                </el-option>
                <el-option
                  label="错题优先"
                  value='错题优先'
                  >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="答案提示:" v-if="title_name=='模拟考试'">
              <el-select v-model="value" placeholder="请选择">
                <el-option
                  label="不显示答案"
                  value='不显示'
                  >
                </el-option>
                <el-option
                  label="显示答案"
                  value='显示'
                  >
                </el-option>
              </el-select>
            </el-form-item> -->
          </el-form>
          <div class="content-button">
            <el-button type="primary" @click="startType">开始考试</el-button>
            <el-button @click="MyExam">考试成绩：{{chengji}}分</el-button>
          </div>
        </div>
    </div>
    <modelExamList ref="modelExamList"></modelExamList>
  </div>
</template>

<script>
import { mockList,getSetting,exammyList,mockWronglist,examList,clearwrong,mycollectq,checkScheme}from'@/api/admin.js'
import {setExectSetting}from '@/utils/auth.js'
import{mapGetters}from 'vuex'
import { getsubject_id,getsubjectTitle,getapplyid,getLearnTime,getisfacetime,getisfacetimezsface,getisphoto} from '@/utils/auth'
import modelExamList from './modelExamList'
export default {
  computed:{
    ...mapGetters(['userinfor','adminUserId','nickname'])
  },
  components:{
    modelExamList
  },
  data() {
    return {
      subject:'',
      radio3:'1',
      gz:'',
      subjectid:'',
      obj:{},//考试配置
      ksInfo:'',
      loading:false,
      xsNum:0,
      chengji:'',
      http:
      process.env.NODE_ENV === "development"
        ? process.env.VUE_APP_BASE_API
        : window.location.href.slice(
            0,
            window.location.href.indexOf("/user")
          ),
    }
  },
  methods: {
    //正式考试
    startType(){
      if(this.http.indexOf('qdshjg')==-1){
        if(this.xsNum<100){
          return this.$message.error('学时不足，无法参加正式考试')
        }
      }else{
        if(this.gz!='企业自主认定'){
          if(this.xsNum<100){
            return this.$message.error('学时不足，无法参加正式考试')
          }
        }
      }
      if(this.obj.人工组卷&&this.obj.人工组卷=="开启"){
        this.$refs.modelExamList.open({
          applyid:getapplyid(),name:'正式考试试卷',obj:this.obj,
          daan:'不显示'
        })
      }else{
        let face = "";
        // if (getisfacetime()) {
        //   face = JSON.parse(getisfacetime()).face;
        // } else
        if(getisphoto()&&getisphoto()!='undefined'&&JSON.parse(getisphoto()).zsface=='开启'){
          if (getisfacetimezsface()) {
            face = JSON.parse(getisfacetimezsface()).face;
            examList({subjectid:this.subjectid,gz:this.gz,applyid:getapplyid(),form:this.form,face}).then(res=>{
              if(res.code==200){
                this.$store.commit('SET_TI',res.data.list)
                let examTime = res.data.scheme_during?res.data.scheme_during:''
                this.$router.push('/simulationzsExam?examid='+res.data.examid+'&gz='+this.gz+'&daan=不显示'+'&subjectid='+getsubject_id()+"&rengong=0"+"&scheme_id="+res.data.scheme_id+'&examTime='+examTime)
              }
            })
          }else{
            checkScheme({applyid: getapplyid(),subjectid: this.subjectid,gz:this.gz}).then(res=>{
              if(res.code==200){
                this.$router.replace('/simulationzsExam')
              }else{
                this.$message.error(res.msg)
              }
            })
          }
        }else{
          examList({subjectid:this.subjectid,gz:this.gz,applyid:getapplyid(),form:this.form,face}).then(res=>{
              if(res.code==200){
                this.$store.commit('SET_TI',res.data.list)
                let examTime = res.data.scheme_during?res.data.scheme_during:''
                this.$router.push('/simulationzsExam?examid='+res.data.examid+'&gz='+this.gz+'&daan=不显示'+'&subjectid='+getsubject_id()+"&rengong=0"+"&scheme_id="+res.data.scheme_id+'&examTime='+examTime)
              }
            })
        }
      }
    },
    //我的试卷
    MyExam(){
      exammyList({ subjectid: getsubject_id(), applyid: getapplyid() }).then(
        (res) => {
          if (res.code == 200) {
            this.$store.commit(
              "SET_MYSJLIST",
              Object.assign(res.data, { title_name: '正式考试'})
            );
            this.chengji =JSON.parse(JSON.stringify(res.data.list)).sort((a,b)=>{
              return b.score-a.score
            })[0].score;
          }
          this.$router.push("/mysjListzs/index");
        }
      );
    },
  },
  created() {
    this.$store.commit('DEL_TI')
    this.subject = this.userinfor.filter(item=>item.subject_id==getsubject_id())[0].subject_id
    this.subjectid = this.userinfor.filter(item=>item.subject_id==getsubject_id())[0].subject_id
    this.gz = this.userinfor.filter(item=>item.subject_id==getsubject_id())[0].gz
    this.xsNum = getLearnTime()
    getSetting({subjectid:this.subjectid,gz:this.gz}).then(res=>{
      if(res.code==200){
        let arr = ['初级','中级','高级','技师']
        if(this.gz=='职业技能等级认定'&&(this.http.indexOf('qdjsxy')!=-1||this.http.indexOf('qiye')!=-1||this.http.indexOf('testtjy')!=-1)){
          arr.map(item=>{
            if(getsubjectTitle().indexOf(item)!=-1){
              this.obj = res.data.正式考试[item];
            }
          })
        }else{
          this.obj = res.data.正式考试;
        }
        setExectSetting(Object.assign(this.obj))
      }
    })
    exammyList({ subjectid: getsubject_id(), applyid: getapplyid() }).then(
        (res) => {
          if (res.code == 200&&res.data.list.length!=0) {
            this.chengji = res.data.list.sort((a,b)=>{
              return b.score-a.score
            })[0].score;
          }
        }
      );
  },
  
}
</script>

<style lang="scss" scoped>
@import '~@/styles/utis.scss';
.app-container{
  height:calc( 100vh - 50px) !important;
}
.backgroundClass{
  height:100%;
}
.title_fontSize{
  // line-height: 32px;
  font-size: 18px;
}
.page_code{
  background: #fff;
  width: calc((100% - 72px) / 4);
  height: 166px;
  display: flex;
  flex-direction: column;
  &:hover{
     box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1)
  }
  .button_box{
    height:50px;
    border-top:1px solid #eee;
    line-height:50px;
    span{
      display: inline-block;
      width: 50%;
      line-height:1;
      text-align: center;
      cursor: pointer;
      color:#666666;
    }
  }
}
.titleBox{
    display: flex;
    min-width: 500px;
    border-bottom: 1px solid #EEEEEE;
    padding-bottom:24px;
  }
   .content-box{
    margin:0 auto;
    margin-top:  24px;
    width: 660px;
    min-height: 600px;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding:32px 71px;
    display: flex;
    flex-direction: column;
    align-items: center;
    .content-title{
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    .img_box{
      width: 70px;
      display: flex;
      flex-direction: column;
      align-items: center;
      img{
        width:64px;
      }
      .span{
        padding:24px 0 ;
        font-size: 18px;
      }
    }
    .content-box-title{
      padding:7px 36px;
      background:#EAF7ED;
      margin-bottom:24px ;
      border-radius: 25px;
      span{
        color:#1DC7A3;
        font-size: 14px;
      }
    }
    .form{
      width:50%;
    }
    .content-box-footer{
      padding:16px 18px;
      background:#FEF3F1;
      span{
        color:#F33E34;
        font-size: 16px;
      }
    }
    .content-button{
      margin-top:80px;
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: flex-end;
    }
  }
  .el-form-item{
    margin-bottom: 24px;
  }
  .noneMargin{
    margin-bottom:20px;
  }
  ::v-deep{
    .is-disabled{
      .el-input__inner{
        color:#333;
      }
    }
  }
</style>